package md.mru.frontend.beans;

import md.mru.backend.core.dtos.FolderDto;
import md.mru.backend.core.service.FolderService;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import java.util.List;

/**
 * @author sergiu.marin
 * @since 29.03.2014
 */
@ManagedBean(name = "folderBean")
@SessionScoped
public class FolderAdministrationBean extends BackingBean {

    @ManagedProperty(value = "#{folderService}")
    private FolderService folderService;

    private FolderDto selectedFolder;
    private List<FolderDto> folders;

    public void init() {
    }

    public String displayFolderInfo(long folderId) {
        this.selectedFolder = folderService.getFolder(folderId);
        return "person-folder";
    }

    public void savePersonalInfo() {
        folderService.save(selectedFolder);
    }

    public String saveFolderData() {
        folderService.save(selectedFolder);
        return "person-folder";
    }

    public String navigateToCreateFolder() {
        return "new-folder";
    }

    public String navigateToFolderList() {
        this.folders = folderService.getFolders();
        return "list-folder";
    }

    public FolderDto getSelectedFolder() {
        if (selectedFolder == null) {
            selectedFolder = new FolderDto();
        }
        return selectedFolder;
    }

    public void setSelectedFolder(FolderDto selectedFolder) {
        this.selectedFolder = selectedFolder;
    }

    public void setFolderService(FolderService folderService) {
        this.folderService = folderService;
    }

    public List<FolderDto> getFolders() {
        return folders;
    }
}
